package com.haoshui.controller;


import com.haoshui.domain.ResponseResult;
import com.haoshui.domain.entity.Article;
import com.haoshui.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("article")
@Api( description = "文章接口")
public class ArticleController {

    @Autowired
    private ArticleService articleService;


    @GetMapping("/list")
    @ApiOperation(value = "获取文章", notes = "获取文章列表")
    public List<Article> test(){
        return articleService.list();
    }

    /**
     * 查找最热的10篇文章
     * @return
     */
    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList() {
        ResponseResult<Article> responseResult = articleService.hotArticleList();
        return responseResult;
    }

    /**
     * 用页的方式查找文章列表
     * @param pageNum
     * @param pageSize
     * @param categoryId
     * @return
     */
    @GetMapping("/articleList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "页大小"),
            @ApiImplicitParam(name="categoryId", value = "种类Id")
    }

    )
    public ResponseResult articleList(Integer pageNum, Integer pageSize, Long categoryId){
        return articleService.articleList( pageNum,  pageSize, categoryId);
    }

    /**
     * 获取文章详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable("id") Long id){
        return articleService.getArticleDetail(id);
    }

    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }


}
